package cn.hc.mq.tags5;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/9/19 21:57
 */
public class FilterBySQLProducer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        TransactionMQProducer producer = new TransactionMQProducer("pg");
        producer.setNamesrvAddr("rocketmqOS1:9876;rocketmqOS2:9876");
        producer.start();

        for (int i = 0; i < 10; i++) {
            byte[] body = ("Hi, filter_by_sql" + i).getBytes();
            Message msg = new Message("filterTopic", "myTag", body);
            // 事先埋入用户属性age
            msg.putUserProperty("age", i + "");
            SendResult sendResult = producer.send(msg);
            System.out.println("发送结果：" + sendResult);
        }
        producer.shutdown();
    }
}
